//
//  YTOrderDetailViewController.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/6/21.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTOrderDetailViewController.h"
#import "YTTabBarViewController.h"
#import "YTOrderFlowViewController.h"
#import "YTOrderDetailViewController+Navigation.h"
#import "YTCarsManagerViewController.h"
#import "YTOrderDetailBottomBtnView.h"
#import "YTOrderDetailViewModel.h"
#import "YTOrderDetailModel.h"
#import "YTLocationManager.h"
#import "YTPickerOrderView.h"
#import "YTPopupView.h"

@interface YTOrderDetailViewController ()<YTPickerOrderViewDelegate>
// 数据
@property (strong, nonatomic) YTOrderDetailViewModel *viewModel;
@property (strong, nonatomic) YTOrderDetailModel *detailModel;
@property (copy, nonatomic) NSString *labelCopyStr;
// 如果不需要显示下面的按钮，置为0
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollBottom;

// 订单状态
@property (weak, nonatomic) IBOutlet UILabel *orderStateText;
@property (weak, nonatomic) IBOutlet UILabel *orderNumText;
@property (weak, nonatomic) IBOutlet UILabel *orderPriceText;
@property (weak, nonatomic) IBOutlet UILabel *cutdownTimeText;
@property (weak, nonatomic) IBOutlet UIImageView *rightArrow;

// 订单信息
@property (weak, nonatomic) IBOutlet UILabel *useCarText;
@property (weak, nonatomic) IBOutlet UILabel *airportNumText;
@property (weak, nonatomic) IBOutlet UILabel *distanceText;
@property (weak, nonatomic) IBOutlet UILabel *passengerNumText;
@property (weak, nonatomic) IBOutlet UILabel *carTypeText;

// 乘客信息
@property (weak, nonatomic) IBOutlet UILabel *passengerNameText;
@property (weak, nonatomic) IBOutlet UILabel *passengerWechatText;
@property (weak, nonatomic) IBOutlet UIButton *passengerTelText;
@property (weak, nonatomic) IBOutlet UIButton *passengerTel2Text;

// 上下车地址
@property (weak, nonatomic) IBOutlet UILabel *onBoard;
@property (weak, nonatomic) IBOutlet UIButton *onBoardBtn;
@property (weak, nonatomic) IBOutlet UILabel *offBoard;
@property (weak, nonatomic) IBOutlet UILabel *offBoardTitle;
@property (weak, nonatomic) IBOutlet UIButton *offBoardBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightConstraint;
@property (strong, nonatomic) CLLocation *loaction;

// 留言
@property (weak, nonatomic) IBOutlet UILabel *leftMessageText;

// 注意事项
@property (weak, nonatomic) IBOutlet UILabel *cautionMessageText;

// 费用说明
@property (weak, nonatomic) IBOutlet UILabel *feeIncludeText;
@property (weak, nonatomic) IBOutlet UILabel *feeNotIncludeText;

// 接单按钮
@property (weak, nonatomic) IBOutlet UIView *btnView;
@property (weak, nonatomic) IBOutlet UIButton *pickerOrderBtn;

// 弹窗
@property (strong, nonatomic) YTPopupView *popView;

/*************************一下部分都是一些可以动态修改的***************************/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *priceDetailHeight;
@property (weak, nonatomic) IBOutlet UIView *priceView;

// 控制附加服务, 正常状态是157.5, 如需显示附加服务,修改高度为285.5,同时显示附加服务view
@property (weak, nonatomic) IBOutlet UIView *additionServicesView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *passengerHeight;

// 车队的提示,只有角色是车队的时候才显示,否则置为0
@property (weak, nonatomic) IBOutlet UIView *orderTipsView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *orderTipsHeight;

// 乘客信息控制, 如果需要显示乘客信息,163;反之10,同时移除下面👇两个view
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *carAndDriverTop;
@property (weak, nonatomic) IBOutlet UILabel *contractTipsView;
@property (weak, nonatomic) IBOutlet UIView *contractView;

// 司机或车辆的信息展示，只有接单以后才显示，默认高度0，接单以后显示两行高度66，一行38
@property (weak, nonatomic) IBOutlet UIView *carAndDriverInfo;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *carAndDriverHeight;

// 航班号控制,如果需要显示,39.5;反之10,同时移除airpTitleText和airportNumText
@property (weak, nonatomic) IBOutlet UILabel *airpTitleText;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *airportHeight;

@end

@implementation YTOrderDetailViewController

#pragma mark - LifeCycle

- (void)initialize {
    [super initialize];
    _labelCopyStr = [NSString string];
    _viewModel = [[YTOrderDetailViewModel alloc] init];
    [self initializeUserinterface];
    
    // 获取地理位置
    [[YTLocationManager manager] singleUpdateLocation:^(CLLocation *location, AMapLocationReGeocode *regeocode) {
        self.loaction = location;
    }];
}

- (void)bindViewModel {
    // 加载订单详情信息
    @weakify(self);
    [_viewModel.detailCommand.executing subscribeNext:[self yt_showHudWithTips:@"加载中..."]];
    [[_viewModel.detailCommand.executionSignals switchToLatest]
     subscribeNext:^(YTOrderDetailModel *model) {
         @strongify(self);
         self.detailModel = model;
         [self loadOrderDataWithModel:model];
    }];
    [_viewModel.detailCommand execute:self.order_id];
    // 抢单
    [[_viewModel.pickOrderCmd.executionSignals switchToLatest]
     subscribeNext:^(NSDictionary *response) {
        @strongify(self);
         [self.popView dismiss:YES];
         if ([response[@"resultCode"] integerValue] == 1000) {
             [self pickSuccess];// 抢单成功！
         } else {
             [self alertWithMsg:response[@"resultMessage"]];
         }
    }];
}

/** UI初始化*/
- (void)initializeUserinterface {
    NSInteger userRole = [YTUtilityManager manager].userModel.userRoleNew;
    // 是否是车队
    if (userRole != 6) {
        _orderTipsView.hidden = YES;
        _orderTipsHeight.constant = 0;
    }
    // 非司机和车队不能接单
    if (userRole == 2 || userRole == 6 || userRole == 7) {
        _pickerOrderBtn.enabled = YES;
        _pickerOrderBtn.backgroundColor = kRedColor;
    }
    // 普通用户，不能接单，但是接单按钮可点，提示去认证
    if (userRole == 1) {
        _pickerOrderBtn.backgroundColor = kGrayColor;
    }
}

- (void)dealloc {}

#pragma mark - 一些动态显示数据加载

// 加载并显示订单数据
- (void)loadOrderDataWithModel:(YTOrderDetailModel *)model {
    _orderStateText.text = model.orderStatusStr;
    _orderNumText.text = model.orderSid;
    _orderPriceText.text = [NSString stringWithFormat:@"%@元", model.driverPrice];
    
    _useCarText.text = model.useTimeSH;
    _airportNumText.text = model.flightNum;
    _distanceText.text = [NSString stringWithFormat:@"%.2fkm", [model.estimatedDistance floatValue]/1000];
    _passengerNumText.text = [NSString stringWithFormat:@"乘客%@人, 行李%@个", model.staffNum, model.luggage];
    _carTypeText.text = model.carTypeName;
    _onBoard.text = model.fromAddress;
    _offBoard.text = model.toAddress;
    // 初始高度
    [self calculateInitHeihgt:model];
    
    // 注意事项及各类费用说明
    _leftMessageText.text = (model.remark.length ? model.remark : @"无");
    _cautionMessageText.text = (model.bookingInfo.length ? model.bookingInfo : @"无");
    _feeIncludeText.text = (model.feeInclude.length ? model.feeInclude : @"无");
    _feeNotIncludeText.text = (model.feeExclusive.length ? model.feeExclusive : @"无");
    // 如果没有给出经纬度，则不显示前往此处按钮
    if (!model.fromLatitude) _onBoardBtn.hidden = YES;
    if (!model.toLatitude) _offBoardBtn.hidden = YES;
}

/** 计算界面的初始高度*/
- (void)calculateInitHeihgt:(YTOrderDetailModel *)model {
    [self showAirportInfo]; // 显示航班号
    [self showPassegerInfo:model]; // 接单以后相关逻辑，比如显示乘客信息，包车路线显示
    [self showTripLine]; // 包车路线信息显示
    
    // 附加服务,后台有返回附加服务列表
    if (model.additionalServiceList.count) {
        _passengerHeight.constant = 167.5 + model.additionalServiceList.count * 28;
        _additionServicesView.hidden = NO;
        for (NSInteger i = 0; i < model.additionalServiceList.count; i++) {
            [self loadAdditionWithModel:model.additionalServiceList[i] index:i isShowPrice:NO];
        }
    }
}

// 显示航班号
- (void)showAirportInfo {
    if (!([_detailModel.secondType isEqualToString:@"101"] || [_detailModel.secondType isEqualToString:@"102"])) {
        [_airpTitleText removeFromSuperview];
        [_airportNumText removeFromSuperview];
        _airportHeight.constant = 10;
        _passengerHeight.constant -= 29.5;
    }
}

// 接单以后相关逻辑，比如显示乘客信息，包车路线显示
- (void)showPassegerInfo:(YTOrderDetailModel *)model {
    if (!_isPicked) {
        // 乘客信息显示, 只有接单以后才能显示
        _carAndDriverTop.constant = 0;
        _carAndDriverHeight.constant = 0;
        [_contractView removeFromSuperview];
        [_contractTipsView removeFromSuperview];
        // 显示接单按钮
        [self showBtnView];
    } else {
        [self showPickedInfo];
    }
}

// 接单以后的相关view显示和控制
- (void)showPickedInfo {
    if (_detailModel.passengerInfo.count) { // 这里一定要判空，不然你会死的很难看
        YTPassengerModel *passenger = _detailModel.passengerInfo[0];
        NSString *placeHolder = @"未提供";
        _passengerNameText.text = (passenger.name.length ? passenger.name : placeHolder);
        if (passenger.phone.length) {
            [_passengerTelText setTitle:passenger.phone forState:UIControlStateNormal];
            [_passengerTelText setTitleColor:kMainBlueColor forState:UIControlStateNormal];
            _passengerTelText.enabled = YES;
        }
        
        if (passenger.overSeasPhone.length) {
            [_passengerTel2Text setTitle:passenger.overSeasPhone forState:UIControlStateNormal];
            [_passengerTel2Text setTitleColor:kMainBlueColor forState:UIControlStateNormal];
            _passengerTel2Text.enabled = YES;
        }
        
        _passengerWechatText.text = (passenger.wechat.length ? passenger.wechat : placeHolder);
    }
    // 显示司导和车辆信息
    [self showCarAndDriver];
    // 底部的各种button显示及点击
    [self bottomBtnAction];
}

// 显示司导和车辆信息
- (void)showCarAndDriver {
    _rightArrow.hidden = NO;
    _carAndDriverTop.constant = 163;
    _carAndDriverHeight.constant = 38;
    NSString *carStr = [NSString stringWithFormat:@"%@", _viewModel.dataModel.carTitle];
    [self creatLeftAndRightLabel:@"接单车辆：" right:carStr superView:_carAndDriverInfo index:0];
    if (isDriverTeam) {
        _carAndDriverHeight.constant = 66;
        [self creatLeftAndRightLabel:@"接单司导："
                               right:_viewModel.dataModel.pickupCardName
                           superView:_carAndDriverInfo index:1];
    }
}

/**
 附加服务显示

 @param model 附加服务数据
 @param index 序列，乘客信息下面显示的时候index从0开始，其他地方从1开始，因为有用车费用
 @param isShowPrice 是否需要显示价格(在顶部显示的时候需要显示价格)
 */
- (void)loadAdditionWithModel:(YTAdditionServiceModel *)model
                        index:(NSInteger)index
                  isShowPrice:(BOOL)isShowPrice {
    NSString *left = [NSString string];
    NSString *right = [NSString string];
    if ([model.name containsString:@"儿童"]) {
        left = @"儿童座椅";
        right = [NSString stringWithFormat:@"%@%zd个", model.name, model.number];
    } else {
        left = model.name;
        right = @"有";
    }
    
    if (isShowPrice) { // 在顶部显示的时候需要显示价格
        right = [NSString stringWithFormat:@"¥ %zd", model.price];
        [self creatLeftAndRightLabel:left right:right superView:_priceView index:index];
    } else {
        [self creatLeftAndRightLabel:left right:right superView:_additionServicesView index:index];
    }
}

/** 显示价格明细*/
- (void)showPriceDetail {
    UILabel *line = [[UILabel alloc] init];
    [_priceView addSubview:line];
    line.backgroundColor = kSaperatorLineColor;
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.and.top.mas_equalTo(_priceView);
        make.left.equalTo(_priceView).offset(15);
        make.height.mas_equalTo(0.5);
    }];
    
    [self creatLeftAndRightLabel:@"用车费用"
                           right:[NSString stringWithFormat:@"¥ %@", _viewModel.dataModel.driverPrice]
                       superView:_priceView index:0];
    for (NSInteger i = 0; i < _viewModel.dataModel.additionalServiceList.count; i++) {
        [self loadAdditionWithModel:_viewModel.dataModel.additionalServiceList[i]
                              index:i + 1 isShowPrice:YES]; // 0位置是用车费用
    }
}

/** 包车路线信息显示*/
- (void)showTripLine {
    _offBoardTitle.hidden = YES;
    _offBoardBtn.hidden = YES;
    _leftConstraint.constant = -70;
    _rightConstraint.constant = -70;
    UILabel *line = [[UILabel alloc] init];
    line.backgroundColor = kSaperatorLineColor;
    [_offBoard.superview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_offBoard.mas_top);
        make.left.and.right.equalTo(_offBoard.superview);
        make.height.mas_equalTo(0.5);
    }];
    if (_detailModel.schedule.count) {
        for (YTScheduleModel *model in _detailModel.schedule) {
            NSString *content = (model.content.length ? model.content : @"客人未提供详细路线,见面沟通哟～");
            _offBoard.text = [_offBoard.text stringByAppendingString:[NSString stringWithFormat:@"\nDay %@:   %@\n", model.day, content]];
        }
        return;
    }
    
    _offBoard.text = @"\n没有详细的路线规划~";
}

#pragma mark - 业务逻辑

- (void)pickSuccess {
    // 接单成功后要在待接订单列表里面删除这条单子
    if (_pickOrderSuccess) {
        _pickOrderSuccess();
    }
    
    if (isDriver) {
        [UIAlertView bk_showAlertViewWithTitle:@"抢单成功" message:@"恭喜"
                             cancelButtonTitle:@"去看看" otherButtonTitles:nil
                                       handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                                           [self changeTabBack:1];
                                       }];
    } else {
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"请在30分钟内完成司机和车辆指派，否则订单将被释放！"];
        [str setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} range:NSMakeRange(2, 4)];
        [UIAlertView bk_showAlertViewWithTitle:@"抢单成功" message:str.mutableString
                             cancelButtonTitle:@"继续抢单" otherButtonTitles:@[@"前往指派"]
                                       handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                                           if (buttonIndex == 1) { // 派单
                                               self.tabBarController.selectedIndex = 1;
                                           }
                                           [self.navigationController popViewControllerAnimated:YES];
                                       }];
    }
}

#pragma mark - 各种点击Action

// 底部的各种button显示及点击
- (void)bottomBtnAction {
//    switch (_detailModel.status) {
//        case 30: {
            [self rightItems];
            [self showBtnView];
            YTOrderDetailBottomBtnView *bView = [[YTOrderDetailBottomBtnView alloc] initWithFrame:_btnView.bounds titles:@[@"取消订单", @"立即指派"]];
            [_btnView addSubview:bView];
    @weakify(self);
    bView.callBackAction = ^(NSInteger type) {
        @strongify(self);
        [self.popView showWithLayout:YTPopupLayoutMake(YTPopupHorizontalLayoutCenter, YTPopupVerticalLayoutBottom)];
    };
//        }
//            break;
//
//        default:
//            break;
//    }
}

// 显示底部那个承载btn的view
- (void)showBtnView {
    _btnView.hidden = NO;
    _scrollBottom.constant = 44;
}

// 顶部右上角的item
- (void)rightItems {
    UIBarButtonItem *callItem = [[UIBarButtonItem alloc] bk_initWithImage:[UIImage imageNamed:@"order_call"] style:UIBarButtonItemStyleDone handler:^(id sender) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@", _passengerTelText.titleLabel.text]]];
    }];
    
    UIBarButtonItem *msgItem = [[UIBarButtonItem alloc] bk_initWithImage:[UIImage imageNamed:@"order_msg"] style:UIBarButtonItemStyleDone handler:^(id sender) {
        
    }];
    
    self.navigationItem.rightBarButtonItems = @[callItem, msgItem];
}

// 价格明细点击
- (IBAction)priceDetailClickAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    [self.view updateConstraintsIfNeeded];
    // 在不点开的情况下高度是0，点开后每行高度28，底部留10
    CGFloat height = (28 + _viewModel.dataModel.additionalServiceList.count * 28 + 10);
    _priceDetailHeight.constant += (sender.selected ? height : -height);
    [UIView animateWithDuration:0.2 animations:^{
        [self.view layoutIfNeeded];
    }];
    
    if (sender.selected) {
        [self showPriceDetail];
    } else {
        for (UIView *view in _priceView.subviews) {
            [view removeFromSuperview];
        }
    }
}

// 点击前往此处
- (IBAction)navigationAction:(UIButton *)sender {
    if (sender.tag == 200) {
        [self navigationWithCoordinate:CLLocationCoordinate2DMake(_detailModel.fromLatitude, _detailModel.fromLongitude)
                          locationName:_detailModel.fromAddressName];
    } else {
        [self navigationWithCoordinate:CLLocationCoordinate2DMake(_detailModel.toLatitude, _detailModel.toLongitude)
                          locationName:_detailModel.toAddressName];
    }
}

// 订单流显示
- (IBAction)showOrderStream:(UITapGestureRecognizer *)sender {
    if (![_orderStateText.text isEqualToString:@"已确认"]) {
        [self performSegueWithIdentifier:@"YTOrderStream" sender:nil];
    }
}

// 点击抢单按钮并加载车辆列表和优惠券列表
- (IBAction)pickOrderAction:(UIButton *)sender {
    if ([YTUtilityManager manager].userModel.userRoleNew == 1) { // 为通过认证的司导
        [UIAlertView bk_showAlertViewWithTitle:@"友情提示" message:@"您还未通过司导认证\n"
                             cancelButtonTitle:@"立即认证" otherButtonTitles:nil
                                       handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
           [self changeTabBack:4];
        }];
    }
    @weakify(self);
    sender.enabled = NO;
    [SVProgressHUD show];
    [[[_viewModel.loadCarAndBonusCmd.executionSignals switchToLatest] take:1]
     subscribeNext:^(NSDictionary *response) {
         @strongify(self);
         [SVProgressHUD dismiss];
         sender.enabled = YES;
         // 亲爱的维护者，你可能会对下面这段逻辑产生疑惑🤷‍♀️
         // 请不要迷茫，咱们的后台就是这么牛逼，错误不是按照code来的
         // 不同的错误可能是相同的code，所以，现在你还迷茫么？
         // 不迷茫了吧！那就干活吧...
         if ([response[@"resultCode"] integerValue] == 1000) {
             [self.popView showWithLayout:YTPopupLayoutMake(YTPopupHorizontalLayoutCenter, YTPopupVerticalLayoutBottom)];
         } else {
             if ([[NSString stringWithFormat:@"%@",response[@"resultMessage"]] containsString:@"车辆"]) { // 没有可接车辆
                 [self notSatisfyCar:response[@"resultMessage"]];
                 return;
             }
             // 没有抢到等其他错误...
             [self alertWithMsg:response[@"resultMessage"]];
         }
     }];
    [_viewModel.loadCarAndBonusCmd execute:nil];
}

// 乘客信息的电话拨打
- (IBAction)callPhoneAction:(UIButton *)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@", sender.titleLabel.text]]];
}

#pragma mark - 复制信息实现

- (IBAction)copyAction:(UILongPressGestureRecognizer *)sender {
    UILabel *label = (UILabel *)sender.view;
    _labelCopyStr = label.text;
    UIMenuController *menu = [UIMenuController sharedMenuController];
    if (menu.isMenuVisible) return;
    UIMenuItem *item = [[UIMenuItem alloc] initWithTitle:@"拷贝" action:@selector(copyTextFunc)];
    menu.menuItems = @[item];
    menu.arrowDirection = UIMenuControllerArrowDown;
    [menu setTargetRect:label.bounds inView:label];
    [menu update];
    [menu setMenuVisible:YES animated:YES];
}

- (void)copyTextFunc {
    UIPasteboard *board = [UIPasteboard generalPasteboard];
    board.string = _labelCopyStr;
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copyTextFunc)) {
        return YES;
    }
    return NO;
}

#pragma mark - 点击抢单以后弹窗

- (YTPopupView *)popView {
    YTPickerOrderView *pickerOrder = [[YTPickerOrderView alloc] initWithFrame:self.view.bounds price:_viewModel.dataModel.driverPrice carBonus:_viewModel.carBonusModel];
    pickerOrder.maxPassenger = _detailModel.staffNum;
    pickerOrder.maxLuggage = _detailModel.luggage;
//    pickerOrder.delegate = self;
//    pickerOrder.backgroundClick = ^{
//        [_popView dismiss:YES];
//    };
    @weakify(self);
    pickerOrder.pickOrderClick = ^(RACTuple *data) {
        @strongify(self);
        [self.viewModel.pickOrderCmd execute:data];
    };
    _popView  = [YTPopupView popupWithContentView:pickerOrder];
    _popView.showType = YTPopupShowTypeSlideInFromBottom;
    _popView.dismissType = YTPopupDismissTypeSlideOutToBottom;
    return _popView;
}

- (void)backgroundClickForDismiss {
    [_popView dismiss:YES];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"YTOrderStream"]) {
        YTOrderFlowViewController *flow = segue.destinationViewController;
        flow.order_id = self.detailModel.orderId;
    }
}

#pragma mark - 暂无可接单车辆

- (void)notSatisfyCar:(NSString *)msg {
    [UIAlertView bk_showAlertViewWithTitle:nil message:msg cancelButtonTitle:@"现在去添加"
                         otherButtonTitles:@[@"不了,先逛逛"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
        if (buttonIndex == 0) {
            [self performSegueWithIdentifier:@"YTAddCarAction" sender:nil];
        } else {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
}

#pragma mark - 显示一个alert，点击确定返回

- (void)alertWithMsg:(NSString *)msg {
    [UIAlertView bk_showAlertViewWithTitle:nil message:msg
                         cancelButtonTitle:@"确定" otherButtonTitles:nil
                                   handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
       [self.navigationController popViewControllerAnimated:YES];
    }];
}

#pragma mark - 切换tab并返回

- (void)changeTabBack:(NSInteger)index {
    self.tabBarController.selectedIndex = index;
    [self.navigationController popViewControllerAnimated:YES];
}

@end
